home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / redakcyjne / programy / Tlen 6.0.1.12 pl / tleninst60112.exe / sdk / Plugin_src / bar-vc / demoplugin.cpp < prev    next >
C/C++ Source or Header  |  2006-09-18  |  5KB  |  202 lines

  1. // demoplugin.cpp : Defines the entry point for the DLL application.
  2. //
  3.  
  4.  
  5. #include "stdafx.h"
  6.  
  7. #include <stdio.h>
  8. #include "../../TlenSources/plugin/plugin_struct.h"
  9. #include "../../TlenSources/plugin/plugin_bar.h"
  10. #include "AggressiveOptimize.h"
  11. #include "resource.h"
  12.  
  13. HINSTANCE hInst;
  14. TLENPLUGINFUNCTIONS *tlen_functions;
  15. HWND bar_window[3];
  16. HBRUSH hBrush = NULL; 
  17.  
  18. TLENPLUGININFO pluginInfo={
  19.     sizeof(TLENPLUGININFO),
  20.     "Doklejane okienka - VC++",
  21.     PLUGIN_API_VERSION,
  22.     MAKE_DWORD_VERSION(1,2,3,4),
  23.     "Plugin tworzy trzy okienka, kt≤re zostaj╣ przyklejone do g│≤wnego okna tlenu.",
  24.     "⌐ Prawa autorskie",
  25.     "Producent",
  26.     "E@mail",
  27.     "http://www",
  28.     0,        
  29.     0,        
  30.     0,        
  31.     0        
  32. };
  33.  
  34. extern "C" __declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD TlenVersion);
  35. extern "C" __declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *tlen_functions);
  36. extern "C" __declspec(dllexport) int UnloadPlugin(void);
  37.  
  38.                 
  39.  
  40. int prefDialog(HWND hWnd, UINT message, WPARAM wparam, LPARAM lparam)
  41. {
  42.     switch (message) {
  43.  
  44.         case WM_INITDIALOG:
  45.         {
  46.                 if (!hBrush) hBrush=::CreateSolidBrush(RGB(150, 220, 220));
  47.                 break;
  48.         }
  49.  
  50.         case WM_ERASEBKGND:
  51.         {
  52.     
  53.                 RECT rc;
  54.                 ::GetClientRect(hWnd, &rc);
  55.                 HDC hdc= (HDC) wparam;
  56.                 
  57.                  FillRect(hdc,&rc,hBrush);
  58.                 
  59.                 return 1;
  60.         }
  61.         
  62.  
  63.         case WM_CTLCOLORSTATIC:
  64.         {
  65.                 RECT rc;
  66.                 HWND hnd = (HWND) lparam;
  67.                 ::GetClientRect(hnd, &rc);
  68.                 HDC hdc= (HDC) wparam;
  69.                 SetTextColor(hdc, RGB(0,0,0));
  70.                 SetBkColor(hdc, RGB(150, 220, 220));
  71.                 
  72.                 return (int) hBrush;
  73.         }
  74.  
  75.         case WM_DESTROY:
  76.         {
  77.                 if (hBrush) 
  78.                 {
  79.                  DeleteObject(hBrush);
  80.                  hBrush = NULL;
  81.                 }
  82.                 break;
  83.         }
  84.  
  85.         //przesuwanie okienka po naci£niΩciu lewego przycisku w client area
  86.         case WM_LBUTTONDOWN: 
  87.         {
  88.                 ReleaseCapture();
  89.                 SendMessage(hWnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
  90.  
  91.                 return 1;
  92.         }
  93.         
  94.  
  95.         //po przeniesieniu okienka musimy poinformowaµ tlen o tym zdarzeniu
  96.         case WM_EXITSIZEMOVE:
  97.         {
  98.                 BarWindowActionDef pdef;
  99.                 InitializeStruct(pdef);
  100.                 pdef.Handle = hWnd;
  101.                 tlen_functions->CallTlenFunction(hInst, TLEN_MANAGE_BAR_WINDOWS, (WPARAM) TLEN_BAR_WINDOW_ACTION_POSCHANGED, (LPARAM) &pdef);
  102.  
  103.                 break;
  104.         }
  105.  
  106.     }
  107.  
  108.     return 0;
  109. }
  110.  
  111.  
  112. BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  113. {
  114.     hInst=hinstDLL;
  115.     return TRUE;
  116. }
  117.  
  118. __declspec(dllexport) TLENPLUGININFO* GetPluginInfo(DWORD tlenVersion)
  119. {
  120.     return &pluginInfo;
  121. }
  122.  
  123. static int CallBackFunc(WPARAM wparam, LPARAM lparam)
  124. {
  125.  switch (wparam)
  126.  {
  127.   //zwracamy lokalizacjΩ doklejonego okienka
  128.   case TLEN_BAR_WINDOW_CALLBACK_GETWINRECT:
  129.   {
  130.    BarWindowActionDef *pos = (BarWindowActionDef *) lparam;
  131.    GetWindowRect(pos->Handle, &(pos->WindowRect));
  132.   }
  133.   break;
  134.  
  135.   //przesuwamy okienko w podane miejsce
  136.   case TLEN_BAR_WINDOW_CALLBACK_MOVE:
  137.   {
  138.    BarWindowActionDef *pos = (BarWindowActionDef *) lparam;
  139.    MoveWindow(pos->Handle, pos->WindowRect.left, pos->WindowRect.top, pos->WindowRect.right - pos->WindowRect.left, pos->WindowRect.bottom - pos->WindowRect.top, TRUE);
  140.   }
  141.   break;
  142.  
  143.   //pokazujemy lub chowamy okienko
  144.   case TLEN_BAR_WINDOW_CALLBACK_SHOW:
  145.   {
  146.    BarWindowActionDef *sdef = (BarWindowActionDef *) lparam;
  147.    sdef->Show ? ShowWindow(sdef->Handle, SW_SHOW) : ShowWindow(sdef->Handle, SW_HIDE);
  148.   }
  149.   break;
  150.  }
  151.  
  152.  return 0;
  153. }
  154.  
  155. __declspec(dllexport) int LoadPlugin(TLENPLUGINFUNCTIONS *functions)
  156. {
  157.     tlen_functions = functions;
  158.     
  159.     //pobieramy uchwyt do g│≤wnego okna tlenu
  160.     HWND h = (HWND) tlen_functions->CallTlenFunction(hInst, TLEN_MANAGE_BAR_WINDOWS, TLEN_BAR_WINDOW_ACTION_GETMAINHANDLE, NULL);
  161.  
  162.     //tworzymy trzy okna doklejane
  163.     for (int i = 0; i < 3; i++)
  164.     {
  165.         bar_window[i] = CreateDialog(hInst, MAKEINTRESOURCE(IDD_DIALOG1), h, (DLGPROC)prefDialog);
  166.  
  167.         BarWindowAddDef adddef;
  168.         InitializeStruct(adddef);
  169.  
  170.         char text[64];
  171.         sprintf(text, "Belka nr %d stworzona przez plugin", i + 1);
  172.         SetDlgItemText(bar_window[i], IDC_STATIC1, text);
  173.  
  174.         char id[32];
  175.         sprintf(id, "barplugin_bar%d", i + 1);
  176.  
  177.         adddef.Handle = bar_window[i];
  178.         adddef.CallBackFunction = CallBackFunc;
  179.         adddef.BarID = id;
  180.  
  181.         tlen_functions->CallTlenFunction(hInst, TLEN_MANAGE_BAR_WINDOWS, (WPARAM) TLEN_BAR_WINDOW_ACTION_ADD, (LPARAM) &adddef);
  182.     }
  183.  
  184.     return 0;
  185. }
  186.  
  187. __declspec(dllexport) int UnloadPlugin(void)
  188. {
  189.  
  190.     //niszczymy doklejone okna
  191.     for (int i = 0; i < 3; i++)
  192.     {
  193.      if (bar_window[i])
  194.      {
  195.         tlen_functions->CallTlenFunction(hInst, TLEN_MANAGE_BAR_WINDOWS, (WPARAM) TLEN_BAR_WINDOW_ACTION_REMOVE, (LPARAM) bar_window[i]);
  196.       DestroyWindow(bar_window[i]);
  197.      }
  198.     }
  199.  
  200.     return 0;
  201. }
  202.